﻿@model MobilnyDostawca.ViewModels.PrzesylkiCreateViewModel

@{
    ViewBag.Title = "Dodaj przesyłkę";
}

<h2>Dodaj przesyłkę</h2>

<script src="@Url.Content("~/Scripts/jquery.validate.min.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/jquery.validate.unobtrusive.min.js")" type="text/javascript"></script>

@using (Html.BeginForm()) {
    @Html.ValidationSummary(true)
    <fieldset>
        <legend>Przesyłka</legend>
        <fieldset>
            <legend>Nadawca</legend>
            <div class="editor-label">
            @Html.Label("Imię")
            </div>
            <div class="editor-field">
                @Html.EditorFor(model => model.NadawcaImie)
                @Html.ValidationMessageFor(model => model.NadawcaImie)
            </div>
            <div class="editor-label">
            @Html.Label("Nazwisko")
            </div>
            <div class="editor-field">
                @Html.EditorFor(model => model.NadawcaNazwisko)
                @Html.ValidationMessageFor(model => model.NadawcaNazwisko)
            </div>
            <div class="editor-label">
            @Html.Label("Adres")
            </div>
            <div class="editor-field">
                @Html.EditorFor(model => model.NadawcaAdres)
                @Html.ValidationMessageFor(model => model.NadawcaAdres)
            </div>
            <div class="editor-label">
            @Html.Label("Telefon")
            </div>
            <div class="editor-field">
                @Html.EditorFor(model => model.NadawcaTelefon)
                @Html.ValidationMessageFor(model => model.NadawcaTelefon)
            </div>
            <div class="editor-label">
            @Html.LabelFor(model => model.NadawcaRegion, "Region")
            </div>
            <div class="editor-field">
                @Html.DropDownList("NadawcaRegion", Model.NadawcaRegiony, string.Empty, new { id = "NadawcaRegionyID" })
                @Html.ValidationMessageFor(model => model.NadawcaRegion)
            </div>
            <div class="editor-label">
            @Html.LabelFor(model => model.NadawcaSubregion, "Subregion")
            </div>
            <div class="editor-field">
                @Html.DropDownList("NadawcaSubregion",Enumerable.Empty<SelectListItem>(), string.Empty, new { id = "NadawcaSubregionyID" })
                @Html.ValidationMessageFor(model => model.NadawcaSubregion)
            </div>
        </fieldset>
        <fieldset>
            <legend>Odbiorca</legend>
            <div class="editor-label">
            @Html.Label("Imię")
            </div>
            <div class="editor-field">
                @Html.EditorFor(model => model.OdbiorcaImie)
                @Html.ValidationMessageFor(model => model.OdbiorcaImie)
            </div>
            <div class="editor-label">
            @Html.Label("Nazwisko")
            </div>
            <div class="editor-field">
                @Html.EditorFor(model => model.OdbiorcaNazwisko)
                @Html.ValidationMessageFor(model => model.OdbiorcaNazwisko)
            </div>
            <div class="editor-label">
            @Html.Label("Adres")
            </div>
            <div class="editor-field">
                @Html.EditorFor(model => model.OdbiorcaAdres)
                @Html.ValidationMessageFor(model => model.OdbiorcaAdres)
            </div>
            <div class="editor-label">
            @Html.Label("Telefon")
            </div>
            <div class="editor-field">
                @Html.EditorFor(model => model.OdbiorcaTelefon)
                @Html.ValidationMessageFor(model => model.OdbiorcaTelefon)
            </div>
            <div class="editor-label">
            @Html.LabelFor(model => model.OdbiorcaRegion, "Region")
            </div>
            <div class="editor-field">
                
                @Html.DropDownList("OdbiorcaRegion", Model.OdbiorcaRegiony, string.Empty, new { id = "OdbiorcaRegionyID" })
                @Html.ValidationMessageFor(model => model.OdbiorcaRegion)
            </div>
            <div class="editor-label">
            @Html.LabelFor(model => model.OdbiorcaSubregion, "Subregion")
            </div>
            <div class="editor-field">
                @Html.DropDownList("OdbiorcaSubregion",Enumerable.Empty<SelectListItem>(), string.Empty, new { id = "OdbiorcaSubregionyID" })
                @Html.ValidationMessageFor(model => model.OdbiorcaSubregion)
            </div>
        </fieldset>
        <p>
            <input type="submit" value="Dodaj"/>
        </p>
    </fieldset>
}

<div>
    @Html.ActionLink("Wróć do listy", "Index")
</div>

<script type="text/javascript">
    $('#NadawcaRegionyID').change(function () {
        var selectedRegion = $(this).val();
        if (selectedRegion != null && selectedRegion != '') {
            $.getJSON('@Url.Action("GetSubregionsForRegion")', { region: selectedRegion }, function (subregions) {
                var subregionsSelect = $('#NadawcaSubregionyID');
                subregionsSelect.empty();
                $.each(subregions, function (index, subregion) {
                    subregionsSelect.append($('<option/>', {
                        value: subregion.Value,
                        text: subregion.Text
                    }));
                });
            });
        }
    });
</script>

<script type="text/javascript">
    $('#OdbiorcaRegionyID').change(function () {
        var selectedRegion = $(this).val();
        if (selectedRegion != null && selectedRegion != '') {
            $.getJSON('@Url.Action("GetSubregionsForRegion")', { region: selectedRegion }, function (subregions) {
                var subregionsSelect = $('#OdbiorcaSubregionyID');
                subregionsSelect.empty();
                $.each(subregions, function (index, subregion) {
                    subregionsSelect.append($('<option/>', {
                        value: subregion.Value,
                        text: subregion.Text
                    }));
                });
            });
        }
    });
</script>